document.addEventListener('DOMContentLoaded', function () {
    const leftBtn = document.querySelector('.culturetour-leftbtn');
    const rightBtn = document.querySelector('.culturetour-rightbtn');
    const images = document.querySelectorAll('.culturetour-picture img');
    const introduces = document.querySelectorAll('.culturetour-introduce');
    
    let currentIndex = 0;

    function updateView() {
        // 更新图片的显示状态
        images.forEach((img, index) => {
            img.classList.remove('active');
            if (index === currentIndex) {
                img.classList.add('active');
            }
        });

        // 更新文字的显示状态
        introduces.forEach((intro, index) => {
            intro.classList.remove('active');
            if (index === currentIndex) {
                intro.classList.add('active');
            }
        });

        // 调整图片容器的位置来实现切换效果
        const offset = -(currentIndex * 220); // 图片的宽度加上间隔
        document.querySelector('.culturetour-picture').style.transform = `translateX(${offset}px)`;
    }

    leftBtn.addEventListener('click', function () {
        currentIndex = (currentIndex === 0) ? images.length - 1 : currentIndex - 1;
        updateView();
    });

    rightBtn.addEventListener('click', function () {
        currentIndex = (currentIndex === images.length - 1) ? 0 : currentIndex + 1;
        updateView();
    });

    // 初始化显示
    updateView();
});